package com.zqxq.lottery.service.expert.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.lottery.common.utils.CommonUtil;
import com.zqxq.lottery.entity.po.export.ExpertFollowPO;
import com.zqxq.lottery.mapper.expert.ExpertFollowMapper;
import com.zqxq.lottery.service.expert.IExpertFollowService;
import com.zqxq.lottery.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ExpertFollowServiceImpl extends ServiceImpl<ExpertFollowMapper, ExpertFollowPO> implements IExpertFollowService {

    @Override
    public int follow(Long expert_id, Long fans_id, Integer status) {
        ExpertFollowPO expertFollowPO = new ExpertFollowPO();
        expertFollowPO.setExpert_id(expert_id);
        expertFollowPO.setFans_id(fans_id);
        expertFollowPO = baseMapper.selectOne(expertFollowPO);
        if (expertFollowPO == null){
            expertFollowPO = new ExpertFollowPO();
            expertFollowPO.setExpert_id(expert_id);
            expertFollowPO.setFans_id(fans_id);
            expertFollowPO.setStatus(status);
            return baseMapper.insert(expertFollowPO);
        }
        expertFollowPO.setStatus(status);
        return baseMapper.updateById(expertFollowPO);
//        Wrapper<ExpertFollowPO> wrapper = new EntityWrapper<>();
//        wrapper.eq("expert_id",expert_id);
//        wrapper.eq("fans_id",fans_id);
//        List<ExpertFollowPO> followPOs = baseMapper.selectList(wrapper);
//        ExpertFollowPO expertFollowPO = new ExpertFollowPO();
//        expertFollowPO.setExpert_id(expert_id);
//        expertFollowPO.setFans_id(fans_id);
//        expertFollowPO.setStatus(status);
//        if(followPOs.size()>0){
//            expertFollowPO.setId(followPOs.get(0).getId());
//            expertFollowPO.setUpdate_time(DateUtil.getCurrentDate());
//            return baseMapper.updateById(expertFollowPO);
//        }else {
//            return baseMapper.insert(expertFollowPO);
//        }
    }
}
